package com.fany.fastsearcher.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.fany.utils.SystemUtils;

/**
 * Created by FANY on 2014/10/29.
 */
public class BaseActivity extends Activity
{
    private int _originTopMargin = 0;
    private int _originHeight = SystemUtils.getScreenHeight();
    private boolean _isFullScreen = true;
    private View _contentParent;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    private void setFullScreen()
    {
        if (_contentParent == null)
        {
            _contentParent = getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
        }
        ViewGroup.LayoutParams params = _contentParent.getLayoutParams();
        if (ViewGroup.MarginLayoutParams.class.isAssignableFrom(params.getClass()))
        {
            ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
            marginParams.setMargins(marginParams.leftMargin, _originTopMargin, marginParams.rightMargin,
                    _originHeight);
        }
        _contentParent.requestLayout();
    }

    private void setHalfScreen()
    {
        if (_contentParent == null)
        {
            _contentParent = getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
        }
        ViewGroup.LayoutParams params = _contentParent.getLayoutParams();
        if (ViewGroup.MarginLayoutParams.class.isAssignableFrom(params.getClass()))
        {
            ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
            marginParams.setMargins(marginParams.leftMargin, _originTopMargin + (int) (_originHeight * 0.3),
                    marginParams.rightMargin, marginParams.bottomMargin + (int) (_originHeight * 0.1));
        }
        _contentParent.requestLayout();
    }

    public void switchScreen(View view)
    {
        if (_isFullScreen)
        {
            setHalfScreen();
        }
        else
        {
            setFullScreen();
        }
        _isFullScreen = !_isFullScreen;
    }
}
